<template>
  <div class="app-container">
    <div style="width: 100%;height: 45px;">
      <div style="width: 150px;float:left;">
        <el-statistic :value="receivingTotal.count" title="总接取数量">
          <template slot="suffix">
            <el-tooltip  class="item" effect="dark" placement="top">
              <div slot="content">
                <div v-if="receivingTotal.moban.length > 0">
                  模版：{{ receivingTotal.moban[0].count }}
                </div>
                <div v-if="receivingTotal.pinban.length > 0">
                  拼版：{{ receivingTotal.pinban[0].count }}
                </div>
                <div v-if="receivingTotal.meigong.length > 0">
                  美工：{{ receivingTotal.meigong[0].count }}
                </div>
                <div v-if="receivingTotal.sku.length > 0">
                  SKU：{{ receivingTotal.sku[0].count }}
                </div>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </template>
        </el-statistic>
      </div>
      <div style="width: 150px;float:left;">
        <el-statistic :value="receivingTotal.finished_count" title="已完成数量">
          <template slot="suffix">
            <el-tooltip  class="item" effect="dark" placement="top">
              <div slot="content">
                <div v-if="receivingTotal.moban.length > 0">
                  模版：{{ receivingTotal.moban[0].finished_count }}
                </div>
                <div v-if="receivingTotal.pinban.length > 0">
                  拼版：{{ receivingTotal.pinban[0].finished_count }}
                </div>
                <div v-if="receivingTotal.meigong.length > 0">
                  美工：{{ receivingTotal.meigong[0].finished_count }}
                </div>
                <div v-if="receivingTotal.sku.length > 0">
                  SKU：{{ receivingTotal.sku[0].finished_count }}
                </div>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </template>
        </el-statistic>
      </div>
      <div style="width: 150px;float:left;">
        <el-statistic :value="receivingTotal.unfinished_count" title="未完成数量">
          <template slot="suffix">
            <el-tooltip  class="item" effect="dark" placement="top">
              <div slot="content">
                <div v-if="receivingTotal.moban.length > 0">
                  模版：{{ receivingTotal.moban[0].unfinished_count }}
                </div>
                <div v-if="receivingTotal.pinban.length > 0">
                  拼版：{{ receivingTotal.pinban[0].unfinished_count }}
                </div>
                <div v-if="receivingTotal.meigong.length > 0">
                  美工：{{ receivingTotal.meigong[0].unfinished_count }}
                </div>
                <div v-if="receivingTotal.sku.length > 0">
                  SKU：{{ receivingTotal.sku[0].unfinished_count }}
                </div>
              </div>
              <i class="el-icon-question"></i>
            </el-tooltip>
          </template>
        </el-statistic>
      </div>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="我的任务" name="first">
        <el-form :model="queryUserTaskParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="产品编码" prop="productCode">
            <el-input v-model="queryUserTaskParams.productCode" @keyup.enter.native="getLists" placeholder="请输入产品编码" style="width: 100%"></el-input>
          </el-form-item>
          <el-form-item label="发布人" prop="userId">
            <el-select v-model="queryUserTaskParams.userId" placeholder="请选择发布人" filterable clearable @keyup.enter.native="getLists" style="width: 100%;">
              <el-option v-for="dict in userIdList" :key="dict.user_id" :label="dict.nickName" :value="dict.user_id"/>
            </el-select>
          </el-form-item>
<!--          <el-form-item label="状态" label-width="100px" prop="make">-->
<!--            <el-select v-model="queryUserTaskParams.statusMap" placeholder="请选择状态" filterable clearable @keyup.enter.native="getLists" style="width: 100%;">-->
<!--              <el-option v-for="(item, index) in ['模版未接取', '美工未接取', '拼版未接取', 'SKU未接取', '模版待签字', '美工待签字', 'SKU待签字']" :key="index" :label="item" :value="index"/>-->
<!--            </el-select>-->
<!--          </el-form-item>-->
          <el-form-item label="是否隐藏已完成" label-width="110px" prop="make">
            <el-select v-model="queryUserTaskParams.checkboxGroup" placeholder="请选择是否隐藏已完成" filterable @keyup.enter.native="getLists" style="width: 100%;">
              <el-option v-for="(item, index) in ['是', '否']" :key="index" :label="item" :value="index"/>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-refresh" @click="getLists">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetGetListsQuery">重置</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="warning" @click="transferTask()">转交任务</el-button>
          </el-form-item>
          <right-toolbar :search="false" @queryTable="getLists"></right-toolbar>
        </el-form>
        <el-table v-loading="userLoading" :data="userTaskerpList" @selection-change="handleSelectionChange">
          <el-table-column label="产品编码" fixed align="center" prop="productCode" />
          <el-table-column label="发布人员" align="center" prop="remark" />
          <el-table-column label="日期" align="center" prop="title" />
          <el-table-column label="类别" align="center" prop="type">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.taskerp_type" :value="scope.row.type"/>
            </template>
          </el-table-column>
          <el-table-column label="店铺" align="center" prop="shop" />
          <el-table-column label="是否加急" align="center" prop="emergency">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.emergency" :value="scope.row.emergency"/>
            </template>
          </el-table-column>
          <el-table-column label="参考链接1" align="center" prop="referenceLink">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLink" @click="copyUrl(scope.row.referenceLink)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLink" @click="toUrl(scope.row.referenceLink)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考链接2" align="center" prop="referenceLinkOne">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLinkOne" @click="copyUrl(scope.row.referenceLinkOne)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLinkOne" @click="toUrl(scope.row.referenceLinkOne)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考链接3" align="center" prop="referenceLinkTwo">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLinkTwo" @click="copyUrl(scope.row.referenceLinkTwo)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLinkTwo" @click="toUrl(scope.row.referenceLinkTwo)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考图" align="center" prop="referenceImage">
            <template slot-scope="scope">
              <image-preview :src="scope.row.referenceImage" style="width: 50%;height: 50%;"/>
            </template>
          </el-table-column>
          <el-table-column label="模版数量" align="center" prop="templatesNum" />
          <el-table-column label="模版要求" align="center" width="120px" prop="templateReq" />
          <el-table-column label="尺寸要求" align="center" width="120px" prop="sizeReq" />
          <el-table-column label="主图详情要求" align="center" width="120px" prop="mainImgReq" />
          <el-table-column label="是否需要主图" align="center" width="120px">
            <template slot-scope="scope">
              <span v-for="(item, index) in ['是', '否'][scope.row.mainImages]" :key="index">{{ item }}</span>
            </template>
          </el-table-column>
          <el-table-column label="类目要求" align="center" width="120px" prop="categoryReq" />
          <!--          <el-table-column label="附件" align="center" prop="attachment">-->
          <!--            <template slot-scope="scope">-->
          <!--              <image-preview :src="scope.row.attachment" style="width: 50%;height: 50%;"/>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column label="类型" align="center" prop="complexity">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.complexity" :value="scope.row.complexity"/>
            </template>
          </el-table-column>
          <!--          <el-table-column v-if="postIds.includes(10)" label="是否通过" align="center" prop="didItPass">-->
          <!--            <template slot-scope="scope">-->
          <!--              <span v-for="item in [{ value: '0', label: '驳回'}, { value: '1', label: '通过'}]" :key="item.value" v-if="scope.row.examineAttachment == item.value">{{ item.label }}</span>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column v-if="postIds.includes(10)" label="审核附件" align="center" prop="examineAttachment"/>
          <!--          <el-table-column v-if="postIds.includes(10)" label="驳回意见" align="center" prop="finalRejection">-->
          <!--            <template slot-scope="scope">-->
          <!--              {{ scope.row.status == 3?scope.row.finalRejection:"" }}-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column label="模版素材" align="center" prop="templateMaterial" />
          <el-table-column label="任务状态" align="center" prop="status" width="100px">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.taskerp_status" :value="scope.row.status"/>
            </template>
          </el-table-column>
          <!--          <el-table-column v-if="postIds.includes(11)" label="驳回意见" align="center" prop="artisticFinalRejection">-->
          <!--            <template slot-scope="scope">-->
          <!--              {{ scope.row.status == 9?scope.row.artisticFinalRejection:"" }}-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          (roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator'))
          <el-table-column v-if="postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版接取人员" align="center" prop="receiveTasksPerson" />
          <el-table-column v-if="postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版接取时间" align="center" prop="templateAcceptTime" />
          <el-table-column v-if="postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版完成时间" align="center" prop="templateCompleteTime" />
          <el-table-column v-if="postIds.includes(11) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="美工接取人员" align="center" prop="artistAllocation" />
          <el-table-column v-if="postIds.includes(11) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="美工接取时间" align="center" prop="artworkAcceptTime" />
          <el-table-column v-if="postIds.includes(11) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="美工完成时间" align="center" prop="artworkCompleteTime" />
          <el-table-column v-if="postIds.includes(12) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版拼版接取人员" align="center" prop="make" />
          <el-table-column v-if="postIds.includes(12) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版拼版状态" align="center" prop="makeStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.make_status" :value="scope.row.makeStatus"/>
            </template>
          </el-table-column>
          <el-table-column v-if="postIds.includes(12) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版拼版接取时间" align="center" prop="typesettingAcceptTime" />
          <el-table-column v-if="postIds.includes(12) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan')" label="模版拼版完成时间" align="center" prop="typesettingCompleteTime" />
          <el-table-column v-if="postIds.includes(13) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="sku接取人" align="center" prop="sku" />
          <el-table-column v-if="postIds.includes(13) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="SKU接取时间" align="center" prop="skuAcceptTime" />
          <el-table-column v-if="postIds.includes(13) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('mobanzuzhang')" label="SKU完成时间" align="center" prop="skuCompleteTime" />
          <!--          <el-table-column label="成品" align="center">-->
          <!--            <template slot-scope="scope">-->
          <!--              <el-button type="text" icon="el-icon-download" @click="getdownloadUrl(scope.row)">成品下载</el-button>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column label="操作" width="150px" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <!--              <el-button type="text" v-if="scope.row.status == 1" icon="el-icon-download" @click="handleExamineDownload(scope.row)">素材下载</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 1 && (postIds.includes(10) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 3 && (postIds.includes(10) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">重新审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 2 && (postIds.includes(10) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="handleUpdateWithdrawExamine(scope.row, 1)">撤回审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 4 && (postIds.includes(10) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交素材</el-button>-->
              <el-button type="text" v-if="scope.row.status == 1 && (postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交素材</el-button>
              <el-button type="text" v-if="scope.row.status >= 4 && scope.row.makeStatus == 0 && scope.row.type == 0 && (postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="allocationMake(scope.row, 1)">分配拼版</el-button>
              <el-button type="text" v-if="scope.row.status >= 4 && scope.row.makeStatus == 0 && scope.row.type == 0 && (postIds.includes(10) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('mobanzuzhang'))" icon="el-icon-edit" @click="allocationMake(scope.row, 4)">无需分配拼版</el-button>
              <!--              <el-button type="text" v-if="(scope.row.status == 7 || scope.row.makeStatus == 2) && scope.row.templateMaterial" icon="el-icon-download" @click="handleExamineDownload(scope.row)">素材下载</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 7  && (postIds.includes(11) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 9  && (postIds.includes(11) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">重新审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 8  && (postIds.includes(11) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateWithdrawExamine(scope.row, 7)">撤回审核</el-button>-->
              <!--              <el-button type="text" v-if="scope.row.status == 10 && (postIds.includes(11) || roles.includes('admin') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交成品</el-button>-->
              <el-button type="text" v-if="scope.row.status == 7  && (postIds.includes(11) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交成品</el-button>
              <el-button type="text" v-if="scope.row.status == 13 && (postIds.includes(13) || roles.includes('admin') || roles.includes('zongjian') || roles.includes('meigongzhuguan') || roles.includes('administrator') || roles.includes('meigongzuzhang'))" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交SKU成品</el-button>
              <el-button type="text" v-if="(postIds.includes(12) || roles.includes('mobanzuzhang')) && scope.row.makeStatus == 2" icon="el-icon-edit" @click="handleUpdateExamine(scope.row)">提交成品</el-button>

              <el-button type="text" v-if="!scope.row.staff && scope.row.status != 1 && scope.row.status != 7 && scope.row.status != 13 && scope.row.makeStatus != 2" icon="el-icon-edit" @click="handleUpdateExamine(scope.row, 2)">
                {{ postIds.includes(10)?'修改素材':postIds.includes(1) || postIds.includes(12)?'修改成品':'修改SKU成品' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="totalUser>0"
          :total="totalUser"
          :page.sync="queryUserTaskParams.pageNum"
          :limit.sync="queryUserTaskParams.pageSize"
          @pagination="getLists"
        />
      </el-tab-pane>

      <el-tab-pane label="任务列表" name="second">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="日期" prop="title">
            <el-date-picker v-model="timeRanges" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 340px;" @keyup.enter.native="handleQuery"></el-date-picker>
          </el-form-item>
          <el-form-item label="产品编码" prop="productCode">
            <el-input v-model="queryParams.productCode" @keyup.enter.native="handleQuery" placeholder="请输入产品编码" style="width: 100%"></el-input>
          </el-form-item>
          <el-form-item label="发布人" prop="userId">
            <el-select v-model="queryParams.userId" placeholder="请选择发布人" filterable clearable @keyup.enter.native="handleQuery" style="width: 100%;">
              <el-option v-for="dict in userIdList" :key="dict.user_id" :label="dict.nickName" :value="dict.user_id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="店铺" prop="shop">
            <el-select v-model="queryParams.shop" @keyup.enter.native="handleQuery" filterable placeholder="请选择店铺" clearable style="width: 100%;">
              <el-option v-for="(item, index) in ['乐艺贴饰', '始发旗舰店', '济南中呈商贸有限公司', '九变定制旗舰店', '九变定制文具', '搜途办公专营店', '哲众旗舰店', 'jnjb2008', '派依倍旗舰店', '智詹官方旗舰店', '锦玉轩家纺家具官方旗舰店', '中奥数码电器', '迪士普数码电器官方旗舰店', '素锦留旗舰店', '起辰', '星耀创意贴饰', '翔启扬旗舰店', '丝乐爽旗舰店', '雨恋冰纯旗舰店', '铎金办公专营店', '智呈旗舰店', '世格创意贴饰', '呈讯旗舰店', '华鲁搜途旗舰店', '智宏汇旗舰店', '展迪优文具馆', '中艺创意家居', '董东东2013', '广格宏家纺家具官方旗舰店', '美格鸿旗舰店', '格莱美海报工厂', '九鼎铎金官方旗舰店', '知迅唐办公用品旗舰店', '中展航标识', '中弘图韵官方旗舰店', '宝菁旗舰店', '中奥晋呈旗舰店', '中弘海报2', '屹呈旗舰店', '九鼎铎金旗舰店', '益讯旗舰店', '中慧达旗舰店', '中利呈旗舰店', '画萌文教用具旗舰店']"
                         :key="index" :label="item" :value="item"/>
            </el-select>
          </el-form-item>
          <el-form-item label="是否加急" prop="emergency">
            <el-select v-model="queryParams.emergency" placeholder="请选择是否加急" clearable style="width: 100%;">
              <el-option v-for="dict in dict.type.emergency" :key="dict.value" :label="dict.label" :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="类型" prop="complexity">
            <el-select v-model="queryParams.complexity" @keyup.enter.native="handleQuery" placeholder="请选择类型" clearable style="width: 240px">
              <el-option v-for="dict in dict.type.complexity" :key="dict.value" :label="dict.label" :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="状态" label-width="100px" prop="make">
            <el-select v-model="queryParams.statusMap" placeholder="请选择状态" filterable clearable @keyup.enter.native="handleQuery" style="width: 100%;">
              <el-option v-for="(item, index) in ['模版未接取', '美工未接取', '拼版未接取', 'SKU未接取']" :key="index" :label="item" :value="index"/>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="taskerpList" @selection-change="handleSelectionChange">
          <el-table-column label="产品编码" fixed align="center" prop="productCode" />
          <el-table-column label="发布人员" align="center" prop="remark" />
          <el-table-column label="日期" align="center" prop="title" />
          <el-table-column label="类别" align="center" prop="type">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.taskerp_type" :value="scope.row.type"/>
            </template>
          </el-table-column>
          <el-table-column label="店铺" align="center" prop="shop" />
          <el-table-column label="是否加急" align="center" prop="emergency">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.emergency" :value="scope.row.emergency"/>
            </template>
          </el-table-column>
          <el-table-column label="参考链接1" align="center" prop="referenceLink">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLink" @click="copyUrl(scope.row.referenceLink)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLink" @click="toUrl(scope.row.referenceLink)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考链接2" align="center" prop="referenceLinkOne">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLinkOne" @click="copyUrl(scope.row.referenceLinkOne)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLinkOne" @click="toUrl(scope.row.referenceLinkOne)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考链接3" align="center" prop="referenceLinkTwo">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.referenceLinkTwo" @click="copyUrl(scope.row.referenceLinkTwo)">复制链接</el-button>
              <el-button type="text" v-if="scope.row.referenceLinkTwo" @click="toUrl(scope.row.referenceLinkTwo)" style="margin: 0;">链接跳转</el-button>
            </template>
          </el-table-column>
          <el-table-column label="参考图" align="center" prop="referenceImage">
            <template slot-scope="scope">
              <image-preview :src="scope.row.referenceImage" style="width: 50%;height: 50%;"/>
            </template>
          </el-table-column>
          <el-table-column label="模版数量" align="center" prop="templatesNum" />
          <el-table-column label="模版要求" align="center" width="120px" prop="templateReq" />
          <el-table-column label="尺寸要求" align="center" width="120px" prop="sizeReq" />
          <el-table-column label="主图详情要求" align="center" width="120px" prop="mainImgReq" />
          <el-table-column label="是否需要主图" align="center" width="120px">
            <template slot-scope="scope">
              <span v-for="(item, index) in ['是', '否'][scope.row.mainImages]" :key="index">{{ item }}</span>
            </template>
          </el-table-column>
          <el-table-column label="类目要求" align="center" width="120px" prop="categoryReq" />
          <!--          <el-table-column label="附件" align="center" prop="attachment">-->
          <!--            <template slot-scope="scope">-->
          <!--              <image-preview :src="scope.row.attachment" style="width: 65px;height: 65px;"/>-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column label="类型" align="center" prop="complexity">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.complexity" :value="scope.row.complexity"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-popconfirm confirm-button-text='确定' cancel-button-text='取消' @confirm="handleUpdateReceiving(scope.row)" icon="el-icon-info" icon-color="red" title="是否确定接取任务？">
                <el-button slot="reference" type="text" icon="el-icon-edit">接取任务</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 添加或修改任务erp对话框 -->
    <el-dialog :title="title" :visible.sync="examineShow" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label="form.status == 1?'审核附件':'素材'" prop="attachment">
          <!--          <el-upload-->
          <!--            ref="upload"-->
          <!--            accept=".png, .jpg, .jpeg, .psd, .ai, .rar, .zip, .gz"-->
          <!--            :multiple="true"-->
          <!--            :headers="upload.headers"-->
          <!--            action="#"-->
          <!--            :disabled="upload.isUploading"-->
          <!--            :action="upload.url"-->
          <!--            :file-list="fileList"-->
          <!--            :on-remove="handleFileRemove"-->
          <!--            :on-change="handleFileChange"-->
          <!--            :on-success="handleUploadSuccess"-->
          <!--            :auto-upload="false" drag>-->
          <!--            <i class="el-icon-upload"></i>-->
          <!--            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>-->
          <!--            <div class="el-upload__tip text-center" slot="tip">-->
          <!--              <span>仅允许导入.png, .jpg, .jpeg, .psd, .ai, .rar, .zip, .gz格式文件。</span>-->
          <!--            </div>-->
          <!--          </el-upload>-->

          <el-input type="textarea" v-model="attachment" placeholder="请输入地址" style="width: 100%"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="examineShow = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改任务erp对话框 -->
    <el-dialog title="" :visible.sync="transferTaskShow" width="800px" append-to-body>
      <el-table ref="singleTable" :data="tableData" style="width: 100%">
        <el-table-column label="产品编码" fixed align="center" prop="productCode" />
        <el-table-column label="模版人员" width="160px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.receiveTasksPerson" :disabled="scope.row.status != 1 && (postIds.includes(10) || roles.includes('zongjian') || roles.includes('meigongzhuguan'))" filterable placeholder="请选择">
              <el-option v-for="item in receivedTenList" :key="item.userId" :label="item.state" :value="item.userId+''"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="美工人员" width="160px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.artistAllocation" :disabled="scope.row.status != 7 && (postIds.includes(11) || roles.includes('zongjian') || roles.includes('mobanzuzhang'))" filterable placeholder="请选择">
              <el-option v-for="item in receivedElevenList" :key="item.userId" :label="item.state" :value="item.userId+''"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="SKU人员" width="160px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.sku" :disabled="scope.row.status != 13 && (postIds.includes(13) || roles.includes('zongjian') || roles.includes('mobanzuzhang'))" filterable placeholder="请选择">
              <el-option v-for="item in receivedElevenList" :key="item.userId" :label="item.state" :value="item.userId+''"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="拼版人员" width="160px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.make" :disabled="scope.row.makeStatus != 2 && (postIds.includes(12) || roles.includes('zongjian') || roles.includes('meigongzhuguan'))" filterable placeholder="请选择">
              <el-option v-for="item in receivedTwelveList" :key="item.userId" :label="item.state" :value="item.userId+''"></el-option>
            </el-select>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitTransferTaskForms">确 定</el-button>
        <el-button @click="transferTaskShow = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { exportExcel, getTaskerp, listTaskerp, updateTaskerp, receivingEdit, getUserIdList } from "@/api/business/taskerp.js";
import { listReceived, selectUserRole, getTaskCompletionStatistics } from "@/api/business/received";
import ResizeMixin from "@/layout/mixin/ResizeHandler";
import {getToken} from "@/utils/auth";
import {parseTime} from "@/utils/ruize";
import axios from "axios";
import {getUser} from "@/api/system/user";

export default {
  dicts: ['complexity', 'taskerp_type', 'emergency', 'taskerp_status', 'make_status'],
  name: "Taskerp",
  mixins: [ResizeMixin],
  data() {
    return {
      // 遮罩层
      loading: true,
      userLoading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 我的任务总条数
      totalUser: 0,
      // 任务erp表格数据
      taskerpList: [],
      userTaskerpList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      examineShow: false,
      examineModifyShow: null,
      activeName: "first",
      timeRanges: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        title: null,
        type: null,
        state: null,
        shop: null,
        emergency: null,
        productCode: null,
        beginTime: null,
        endTime: null,
        complexity: null
      },
      queryUserTaskParams: {
        pageNum: 1,
        pageSize: 10,
        checkboxGroup: 0,
        userId: null,
        statusMap: null,
      },
      // 表单参数
      form: {},
      attachment: "",
      // 表单校验
      rules: {
        // artisticFinishedProduct: [
        //   { required: true, message: "美工成品不能为空", trigger: "blur" }
        // ],
      },
      // 客服绩效导入参数
      upload: {
        isUploading: false,
        // 弹出层标题（客服绩效导入）
        title: "",
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/oldName"
      },
      fileList: [],
      postIds: [],
      roles: "",
      transferTaskShow: false,
      receivedTenList: [],
      receivedElevenList: [],
      receivedTwelveList: [],
      skuList: [],
      tableData: [],
      userIdList: [],
      receivingTotal: {
        count: 0,
        finished_count: 0,
        unfinished_count: 0,
        moban: [],
        meigong: [],
        pinban: [],
        sku: []
      },
    };
  },
  created() {
    this.userLoading = true;
    this.roles = this.$store.getters.roles.join();
    getUser(this.$store.getters.userId).then(response => {
      this.postIds = response.postIds.join()
      this.getLists();
      this.getList();
    });
    this.getUserIdList()
    this.getTotal()
  },
  methods: {
    getTotal(){
      getTaskCompletionStatistics({userId: this.$store.getters.userId}).then(response => {
        const moban = response.data.filter(row => row.post === "模版");
        const meigong = response.data.filter(row => row.post === "美工");
        const pinban = response.data.filter(row => row.post === "拼版");
        const sku = response.data.filter(row => row.post === "sku");
        this.receivingTotal.moban = moban
        this.receivingTotal.meigong = meigong
        this.receivingTotal.pinban = pinban
        this.receivingTotal.sku = sku
        response.data.map(i => {
          this.receivingTotal.count = parseInt(this.receivingTotal.count) + parseInt(i.count);
          this.receivingTotal.finished_count = parseInt(this.receivingTotal.finished_count) + parseInt(i.finished_count);
          this.receivingTotal.unfinished_count = parseInt(this.receivingTotal.unfinished_count) + parseInt(i.unfinished_count);
        })
      });
    },
    /** 多个文件一起提交*/
    handleFileChange(file, fileList) {
      this.fileList = fileList;
    },
    /** 源文件上传列表删除事件*/
    handleFileRemove() {
      // 源文件删除，同时将hash值清空
      if (this.postIds.includes(10)){
        if (this.form.status == 1){
          this.form.examineAttachment = ''
        }else {
          this.form.templateMaterial = ''
        }
      }else {
        this.form.artisticFinishedProduct = ''
      }
    },
    handleUploadSuccess(res, file) {
      if (res.code === 200) {
        this.fileList.push({ name: res.fileName, url: res.fileName });
        if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')){
          if (this.form.status == 1 || this.form.status == 3){
            this.form.examineAttachment = res.fileName
            this.form.templateMaterial = res.fileName
          }else if (this.form.status == 4){
            this.form.templateMaterial = res.fileName
          }else if (this.form.status == 7 || this.form.status == 9){
            this.form.artisticExamineAttachment = res.fileName
            this.form.artisticFinishedProduct = res.fileName
          }else if (this.form.status == 10){
            this.form.artisticFinishedProduct = res.fileName
          }
        }else if (this.roles.includes('mobanzuzhang')){
          if (this.form.status == 1 || this.form.status == 3){
            this.form.examineAttachment = res.fileName
            this.form.templateMaterial = res.fileName
          }else if (this.form.status == 4){
            this.form.templateMaterial = res.fileName
          }else{
            this.form.makeUrl = res.fileName
          }
        }else if (this.roles.includes('meigongzuzhang')){
          if (this.form.status == 7 || this.form.status == 9){
            this.form.artisticExamineAttachment = res.fileName
            this.form.artisticFinishedProduct = res.fileName
          }else {
            this.form.artisticFinishedProduct = res.fileName
          }
        }else {
          if (this.postIds.includes(10)){
            if (this.form.status == 1 || this.form.status == 3){
              this.form.examineAttachment = res.fileName
              this.form.templateMaterial = res.fileName
            }else {
              this.form.templateMaterial = res.fileName
            }
          }else if (this.postIds.includes(11)){
            if (this.form.status == 7 || this.form.status == 9){
              this.form.artisticExamineAttachment = res.fileName
              this.form.artisticFinishedProduct = res.fileName
            }else {
              this.form.artisticFinishedProduct = res.fileName
            }
          }else if (this.postIds.includes(12)){
            this.form.makeUrl = res.fileName
          }
        }
        this.submitForm()
      } else {
        this.$modal.closeLoading();
        this.$modal.msgError(res.msg);
        this.$refs.upload.handleRemove(file);
      }
    },
    /** 查询任务erp列表 */
    getList() {
      this.loading = true;
      const complexity = this.queryParams.complexity;
      let query = {...this.queryParams};
      if (query.statusMap){
        if (query.statusMap == 0){
          query = {...query, complexity: complexity, type: 0, statusList: [0]}
        }else if (query.statusMap == 1){
          query = {...query, complexity: complexity, type: 1, statusList: [0,6]}
        }else if (query.statusMap == 2){
          query = {...query, complexity: complexity, makeStatus: 1}
        }else if (query.statusMap == 3){
          query = {...query, complexity: complexity, statusList: [12]}
        }
      }else {
        if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')){
          query = {...query, complexity: complexity, statusList: [0,6]}
        }else if (this.roles.includes('mobanzuzhang')){
          query = {...query, complexity: complexity, type: 3, statusList: [0], makeStatus: 2}
        }else if (this.roles.includes('meigongzuzhang')){
          query = {...query, complexity: complexity, type: 1}
        }else {
          if (this.postIds.includes(10)){
            query = {...query, complexity: complexity, type: 0, statusList: [0]}
          }else if (this.postIds.includes(11)){
            query = {...query, complexity: complexity, type: 1, statusList: [0,6]}
          }else if (this.postIds.includes(12)){
            query = {...query, complexity: complexity, makeStatus: 1}
          }else if (this.postIds.includes(13)){
            query = {...query, complexity: complexity, statusList: [12]}
          }
        }
      }
      listTaskerp(query).then(response => {
        this.taskerpList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleClick(){
      this.getLists()
      this.resetQuery()
    },
    getLists() {
      this.userLoading = true;
      const userId = this.$store.getters.userId;
      let query = this.postIds.includes(10)?{receiveTasksPerson: userId}:this.postIds.includes(12)?{make: userId}:{artistAllocation: userId}
      if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')){
        query = {receiveTasksPerson: userId, artistAllocation: userId, make: userId, sku: userId, makeStatus: 3}
      }else if (this.roles.includes('mobanzuzhang')){
        query = {receiveTasksPerson: userId, make: userId, makeStatus: this.queryUserTaskParams.checkboxGroup == 0?6:3, statusList: this.queryUserTaskParams.checkboxGroup == 0?[1,2,3,4,5]:null}
      }else if (this.roles.includes('meigongzuzhang')){
        query = {artistAllocation: userId, sku: userId, makeStatus: 3, statusList: this.queryUserTaskParams.checkboxGroup == 0?[7,8,9,10,11,13,14,15]:null}
      }else {
        if (this.postIds.includes(10)){
          query = {receiveTasksPerson: userId, statusList: this.queryUserTaskParams.checkboxGroup == 0?[1,2,3,4,5]:null}
        }else if (this.postIds.includes(11)){
          query = {artistAllocation: userId, statusList: this.queryUserTaskParams.checkboxGroup == 0?[7,8,9,10,11]:null}
        }else if (this.postIds.includes(12)){
          query = {make: userId, makeStatus: this.queryUserTaskParams.checkboxGroup == 0?5:null}
        }else if (this.postIds.includes(13)){
          query = {sku: userId, statusList: this.queryUserTaskParams.checkboxGroup == 0?[13,14,15]:null}
        }
      }
      // if (query.statusMap == 0){
      //   query.type = 0;
      //   query.statusList = [0]
      // }else if (query.statusMap == 1){
      //   query.statusList = [1]
      // }else if (query.statusMap == 2){
      //   query.statusList = [2]
      // }else if (query.statusMap == 3){
      //   query.type = 1;
      //   query.statusList = [0,6]
      // }else if (query.statusMap == 4){
      //   query.statusList = [7]
      // }else if (query.statusMap == 5){
      //   query.statusList = [8]
      // }else if (query.statusMap == 6){
      //   query.makeStatus = 1
      // }else if (query.statusMap == 7){
      //   query.makeStatus = 2
      // }else if (query.statusMap == 8){
      //   query.statusList = [12]
      // }else if (query.statusMap == 9){
      //   query.statusList = [13]
      // }else if (query.statusMap == 10){
      //   query.statusList = [14]
      // }
      query = {...query, ...this.queryUserTaskParams}
      listTaskerp(query).then(response => {
        this.userTaskerpList = response.rows;
        this.totalUser = response.total;
        this.userLoading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.$refs.upload.clearFiles();
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        type: null,
        templateReq: null,
        sizeReq: null,
        mainImgReq: null,
        categoryReq: null,
        attachment: null,
        complexity: null,
        didItPass: null,
        finalRejection: null,
        templateMaterial: null,
        status: null,
        receiveTasksPerson: null,
        artistAllocation: null,
        artisticFinishedProduct: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        state: null
      };
      this.resetForm("form");
    },
    getUserIdList(){
      getUserIdList().then(res => {
        this.userIdList = res.data
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.timeRanges.length == 2){
        this.queryParams.beginTime = parseTime(this.timeRanges[0], "{y}-{m}-{d}")
        this.queryParams.endTime = parseTime(this.timeRanges[1], "{y}-{m}-{d}")
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timeRanges = []
      this.handleQuery();
    },
    /** 重置按钮操作 */
    resetGetListsQuery() {
      this.queryUserTaskParams = {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        statusMap: null,
      }
      this.getLists()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    copyUrl(url) {
      // 检测用户代理字符串
      const userAgent = navigator.userAgent;
      // 判断是否为IE浏览器
      const isIE = userAgent.indexOf('MSIE ') > -1 || userAgent.indexOf('Trident/') > -1;
      // 判断是否为Edge浏览器
      const isEdge = userAgent.indexOf('Edge/') > -1;
      // 判断是否为Firefox浏览器
      const isFirefox = userAgent.indexOf('Firefox/') > -1;
      // 根据不同浏览器执行不同的复制策略
      if (isIE) {
        // IE浏览器使用旧的方法
        this.copyTextToClipboardIE(url);
      } else if (isEdge || isFirefox) {
        // Edge和Firefox浏览器可能需要权限，尝试使用现代API
        this.copyTextToClipboardModern(url);
      } else {
        // 其他浏览器默认使用现代API
        this.copyTextToClipboardModern(url);
      }
    },
    copyTextToClipboardIE(url) {
      const textArea = document.createElement('textarea');
      textArea.value = url;
      document.body.appendChild(textArea);
      textArea.select();
      try {
        document.execCommand('copy');
        this.$message('文本已复制到剪贴板');
      } catch (err) {
        this.$message.error("无法复制文本");
      }
      document.body.removeChild(textArea);
    },
    copyTextToClipboardModern(url) {
      if (navigator.clipboard) {
        navigator.clipboard.writeText(url).then(() => {
          this.$message('文本已复制到剪贴板');
        }).catch(err => {
          this.$message.error("无法复制文本");
        });
      } else {
        this.copyTextToClipboardIE(url); // 如果现代API不可用，回退到IE的方法
      }
    },
    toUrl(url){
      window.open(url, '_blank');
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加任务erp";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTaskerp(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改任务erp";
      });
    },
    /** 修改按钮操作 */
    handleUpdateReceiving(row) {
      getTaskerp(row.id).then(response => {
        const data = response.data;
        const userId = this.$store.getters.userId;
        let form = {
          id: row.id
        };
        // 定义一个函数来设置表单字段和状态
        const setFormFields = (field, status, timeField) => {
          form[field] = userId;
          form.status = status;
          form[timeField] = parseTime(new Date());
        };

        // 根据角色和状态设置表单字段
        if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')) {
          if (data.status == 0) {
            setFormFields('receiveTasksPerson', 1, 'templateAcceptTime');
          } else if (data.makeStatus == 1 && data.status != 6) {
            setFormFields('make', 2, 'typesettingAcceptTime');
          } else if (data.status == 6) {
            setFormFields('artistAllocation', 7, 'artworkAcceptTime');
          } else if (data.status == 12) {
            setFormFields('sku', 13, 'skuAcceptTime');
          }
        } else if (this.roles.includes('mobanzuzhang')) {
          if (data.status == 0) {
            setFormFields('receiveTasksPerson', 1, 'templateAcceptTime');
          } else if (data.makeStatus == 1) {
            setFormFields('make', 2, 'typesettingAcceptTime');
          }
        } else if (this.roles.includes('meigongzuzhang')) {
          console.log(data, "美工组长")
          if (data.status == 6) {
            setFormFields('artistAllocation', 7, 'artworkAcceptTime');
          } else if (data.status == 12) {
            setFormFields('sku', 13, 'skuAcceptTime');
          }
        } else {
          if (this.postIds.includes(10)) {
            setFormFields('receiveTasksPerson', 1, 'templateAcceptTime');
          } else if (this.postIds.includes(11)) {
            setFormFields('artistAllocation', 7, 'artworkAcceptTime');
          } else if (this.postIds.includes(12)) {
            setFormFields('make', 2, 'typesettingAcceptTime');
          } else if (this.postIds.includes(13)) {
            setFormFields('sku', 13, 'skuAcceptTime');
          }
        }
        console.log(form)
        receivingEdit(form).then(response => {
          this.$modal.msgSuccess("接取成功");
          this.getList();
          this.getLists();
        });
      });
    },
    async transferTask(){
      this.tableData = []
      await selectUserRole().then(r => {
        const mobanzuzhang = r.data.filter(row => row.role_id == "35");
        const meigongzuzhang = r.data.filter(row => row.role_id == "36");
        listReceived({ postList: [ 10 ], pageSize: 1000 }).then(res => {
          this.receivedTenList = [...mobanzuzhang, ...res.rows]
        })
        listReceived({ postList: [ 11 ], pageSize: 1000 }).then(res => {
          this.receivedElevenList = [...meigongzuzhang, ...res.rows]
        })
        listReceived({ postList: [ 12 ], pageSize: 1000 }).then(res => {
          this.receivedTwelveList = [...mobanzuzhang, ...res.rows]
        })
        listReceived({ postList: [ 13 ], pageSize: 1000 }).then(res => {
          this.skuList = [...meigongzuzhang, ...res.rows]
        })
      })
      this.userTaskerpList.map(i => {
        getTaskerp(i.id).then(response => {
          if(i.status == 1){
            this.tableData.push(response.data)
          }else if(i.status == 7){
            this.tableData.push(response.data)
          }else if(i.status == 13){
            this.tableData.push(response.data)
          }else if(i.makeStatus == 2){
            this.tableData.push(response.data)
          }
        });
      })
      this.transferTaskShow = true
    },
    submitTransferTaskForms(){
      let list = [];
      this.tableData.map(i => {
        if(i.status == 1){
          list.push({ id: i.id, receiveTasksPerson: i.receiveTasksPerson })
        }else if(i.status == 7){
          list.push({ id: i.id, artistAllocation: i.artistAllocation })
        }else if(i.status == 13){
          list.push({ id: i.id, sku: i.sku })
        }else if(i.makeStatus == 2){
          list.push({ id: i.id, make: i.make })
        }
      })
      Promise.all(
        list.map(i =>
          updateTaskerp(i)
        )
      ).then(results => {
        console.log(results)
        // 所有删除操作成功完成
        this.tableData = []
        this.$message({ message: '任务转交完成！', type: 'success' });
        this.getLists()
        this.transferTaskShow = false
      }).catch(error => {
        // 处理错误
        console.log(error)
        this.$message.error('任务转交失败，请联系管理员');
      });
    },
    /** 修改按钮操作 */
    handleUpdateExamine(row, type) {
      getTaskerp(row.id).then(response => {
        this.form = response.data;
        this.fileList = []
        this.examineShow = true
        this.examineModifyShow = type
        this.attachment = ""
      });
    },
    allocationMake(row, makeStatus){
      getTaskerp(row.id).then(response => {
        response.data.makeStatus = makeStatus
        updateTaskerp({ id: response.data.id, status: response.data.status == 4?16:null, makeStatus: makeStatus }).then(response => {
          this.$modal.msgSuccess("提交成功");
          this.examineShow = false;
          this.getLists();
        });
      });
    },
    /** 修改按钮操作 */
    handleExamineDownload(row) {
      let urlString = ""
      const _this = this
      // if (this.postIds.includes(10) || row.type == 1){
      //   url = row.attachment;
      // }else {
      urlString = row.templateMaterial;
      // }
      // 假设URLs是以逗号分隔的
      const urls = urlString.split(','); // 根据实际情况，可能需要使用不同的分隔符
      urls.forEach(url => {
        axios({
          url: process.env.VUE_APP_BASE_API + url.trim(), // trim()用于移除字符串两端的空白字符
          method: 'GET',
          responseType: 'blob', // 重要：需要设置响应类型为blob
        }).then(response => {
          console.log(response);
          // 假设每个URL对应的文件名可以通过某种方式获得，这里我们使用url作为文件名
          const fileName = this.getBaseName(url.split('/').pop().split('?')[0]);
          console.log(fileName, "这里执行了吗")
          const fileUrl = window.URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement('a');
          link.href = fileUrl;
          link.setAttribute('download', fileName); // 或者你想要的名字
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link); // 下载后移除元素
          window.URL.revokeObjectURL(fileUrl); // 释放URL对象
        }).catch(error => {
          console.error('下载失败:', error);
        });
      });
    },
    downloadUrl(urlString) {
      // 假设URLs是以逗号分隔的
      const urls = urlString.split(','); // 根据实际情况，可能需要使用不同的分隔符
      urls.forEach(url => {
        axios({
          url: process.env.VUE_APP_BASE_API + url.trim(), // trim()用于移除字符串两端的空白字符
          method: 'GET',
          responseType: 'blob', // 重要：需要设置响应类型为blob
        }).then(response => {
          // 假设每个URL对应的文件名可以通过某种方式获得，这里我们使用url作为文件名
          const fileName = this.getBaseName(url.split('/').pop().split('?')[0]);
          const fileUrl = window.URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement('a');
          link.href = fileUrl;
          link.setAttribute('download', fileName); // 或者你想要的名字
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link); // 下载后移除元素
          window.URL.revokeObjectURL(fileUrl); // 释放URL对象
        }).catch(error => {
          console.error('下载失败:', error);
        });
      });
    },
    getdownloadUrl(row){
      let str = '';
      if (row.templateMaterial !== '' && row.templateMaterial !== null && row.templateMaterial !== undefined) {
        str += (str.length > 0 ? ',' : '') + row.templateMaterial;
      }
      if (row.makeUrl !== '' && row.makeUrl !== null && row.makeUrl !== undefined) {
        str += (str.length > 0 ? ',' : '') + row.makeUrl;
      }
      if (row.artisticFinishedProduct !== '' && row.artisticFinishedProduct !== null && row.artisticFinishedProduct !== undefined) {
        str += (str.length > 0 ? ',' : '') + row.artisticFinishedProduct;
      }
      if (str.length == 0){
        this.$message.error('没有成品！');
      }else {
        this.downloadUrl(str)
      }
    },
    getBaseName(fileName) {
      const underscoreIndex = fileName.indexOf('_');
      const houzui = fileName.split('.')[1]
      if (underscoreIndex !== -1) {
        return fileName.substring(0, underscoreIndex) + '.' + houzui;
      }
      return fileName + '.' + houzui; // 如果没有找到'_'，则返回整个文件名
    },
    getFileNameFromUrl(url) {
      return url.substring(url.lastIndexOf('/') + 1);
    },
    /** 修改按钮操作 */
    handleUpdateWithdrawExamine(row, status) {
      getTaskerp(row.id).then(response => {
        console.log(response)
        response.data.status = status
        updateTaskerp(response.data).then(response => {
          this.$modal.msgSuccess("撤回成功");
          this.examineShow = false;
          this.getLists();
        });
      });
    },
    submitForms(){
      if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')){
        if (this.form.status == 1 || this.form.status == 3){
          this.form.examineAttachment = this.attachment
          this.form.templateMaterial = this.attachment
        }else if (this.form.status == 4){
          this.form.templateMaterial = this.attachment
        }else if (this.form.status == 7 || this.form.status == 9){
          this.form.artisticExamineAttachment = this.attachment
          this.form.artisticFinishedProduct = this.attachment
        }else if (this.form.status == 10){
          this.form.artisticFinishedProduct = this.attachment
        }else if (this.form.status == 13){
          this.form.skuProductUrl = this.attachment
        }
      }else if (this.roles.includes('mobanzuzhang')){
        if (this.form.status == 1 || this.form.status == 3){
          this.form.examineAttachment = this.attachment
          this.form.templateMaterial = this.attachment
        }else if (this.form.status == 4){
          this.form.templateMaterial = this.attachment
        }else{
          this.form.makeUrl = this.attachment
        }
      }else if (this.roles.includes('meigongzuzhang')){
        if (this.form.status == 7 || this.form.status == 9){
          this.form.artisticExamineAttachment = this.attachment
          this.form.artisticFinishedProduct = this.attachment
        }else if (this.form.status == 10){
          this.form.artisticFinishedProduct = this.attachment
        }else if (this.form.status == 13){
          this.form.skuProductUrl = this.attachment
        }
      }else {
        if (this.postIds.includes(10)){
          if (this.form.status == 1 || this.form.status == 3){
            this.form.examineAttachment = this.attachment
            this.form.templateMaterial = this.attachment
          }else {
            this.form.templateMaterial = this.attachment
          }
        }else if (this.postIds.includes(11)){
          if (this.form.status == 7 || this.form.status == 9){
            this.form.artisticExamineAttachment = this.attachment
            this.form.artisticFinishedProduct = this.attachment
          }else if (this.form.status == 10){
            this.form.artisticFinishedProduct = this.attachment
          }else if (this.form.status == 13){
            this.form.skuProductUrl = this.attachment
          }
        }else if (this.postIds.includes(12)){
          this.form.makeUrl = this.attachment
        }
      }
      if (this.examineModifyShow == 2){
        updateTaskerp(this.form).then(response => {
          this.$modal.msgSuccess("提交成功");
          this.examineShow = false;
          this.getLists();
        });
      }else {
        this.submitForm()
      }
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form)
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.roles.includes('admin') || this.roles.includes('zongjian') || this.roles.includes('meigongzhuguan') || this.roles.includes('administrator')){
            if (this.form.status == 1 || this.form.status == 3){
              this.form.status = 2
              this.form.templateCompleteTime = parseTime(new Date())
            }else if (this.form.status == 4){
              this.form.status = 2
              this.form.templateCompleteTime = parseTime(new Date())
            }else if (this.form.status == 7 || this.form.status == 9){
              this.form.status = 8
              this.form.artworkCompleteTime = parseTime(new Date())
              this.form.skuAcceptTime = parseTime(new Date())
            }else if (this.form.status == 10){
              this.form.status = 8
              this.form.artworkCompleteTime = parseTime(new Date())
              this.form.skuAcceptTime = parseTime(new Date())
            }else if (this.form.status == 13){
              this.form.status = 14
              this.form.skuCompleteTime = parseTime(new Date())
            }
          }else if (this.roles.includes('mobanzuzhang')){
            if (this.form.status == 1 || this.form.status == 3){
              this.form.status = 2
              this.form.templateCompleteTime = parseTime(new Date())
            }else if (this.form.status == 4){
              this.form.status = 2
              this.form.templateCompleteTime = parseTime(new Date())
            }else{
              this.form.makeStatus = 3
              this.form.typesettingCompleteTime = parseTime(new Date())
            }
          }else if (this.roles.includes('meigongzuzhang')){
            if (this.form.status == 7 || this.form.status == 9){
              this.form.status = 8
              this.form.artworkCompleteTime = parseTime(new Date())
              this.form.skuAcceptTime = parseTime(new Date())
            }else if (this.form.status == 10){
              this.form.status = 8
              this.form.artworkCompleteTime = parseTime(new Date())
              this.form.skuAcceptTime = parseTime(new Date())
            }else if (this.form.status == 13){
              this.form.status = 14
              this.form.skuCompleteTime = parseTime(new Date())
            }
          }else {
            if (this.postIds.includes(10)){
              if (this.form.status == 1 || this.form.status == 3){
                this.form.status = 2
                this.form.templateCompleteTime = parseTime(new Date())
              }else if (this.form.status == 4){
                this.form.status = 2
                this.form.templateCompleteTime = parseTime(new Date())
              }
            }else if (this.postIds.includes(11)){
              if (this.form.status == 7 || this.form.status == 9){
                this.form.status = 8
                this.form.artworkCompleteTime = parseTime(new Date())
                this.form.skuAcceptTime = parseTime(new Date())
              }else if (this.form.status == 10){
                this.form.status = 8
                this.form.artworkCompleteTime = parseTime(new Date())
                this.form.skuAcceptTime = parseTime(new Date())
              }
            }else if (this.postIds.includes(12)){
              this.form.makeStatus = 3
              this.form.typesettingCompleteTime = parseTime(new Date())
            }else if (this.postIds.includes(13)){
              this.form.status = 14
              this.form.skuCompleteTime = parseTime(new Date())
            }
          }
          this.form.receiveTasksPerson = null;
          this.form.artistAllocation = null;
          updateTaskerp(this.form).then(response => {
            this.$modal.msgSuccess("提交成功");
            this.examineShow = false;
            this.getLists();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除任务erp编号为"' + ids + '"的数据项？').then(function() {
        return delTaskerp(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      exportExcel(this.queryParams).then(() => {
        this.$alert('任务创建成功，请到<strong style="color: #00afff">任务中心</strong>查看进度!', '提示', {
          dangerouslyUseHTMLString: true
        }).catch(()=>{});
      })
    },
  }
};
</script>

<style>
::-webkit-scrollbar {
  width: 0.07rem;
  height: 10px !important;
}
::-webkit-scrollbar-thumb {
  background: black !important;
}
</style>
